// 示例1:

// 输入: pattern = "abba", s = "dog cat cat dog"
// 输出: true
// 示例 2:

// 输入: pattern = "abba", s = "dog cat cat fish"
// 输出: false
// 示例 3:

// 输入: pattern = "aaaa", s = "dog cat cat dog"
// 输出: false

pattern = "aaaa", s = "dog cat cat dog"
pattern = "abba", s = "dog cat cat dog"
pattern = "abba", s = "dog constructor constructor dog"

var wordPattern = function (pattern, s) {
    let obj1 = new Map(), obj2 = new Map(), len = pattern.length
    let arr = s.split(' ')
    if (len !== arr.length) return false
    for (let i = 0; i < len; i++) {
        if (obj1.has(pattern[i]) && obj1.get(pattern[i]) !== arr[i]) {
            return false
        }
        if (obj2.has(arr[i]) && obj2.get(arr[i]) !== pattern[i]) {
            return false
        }
        obj1.set(pattern[i], arr[i])
        obj2.set(arr[i], pattern[i])
    }
    return true;
};

console.log(wordPattern(pattern, s));
